﻿<UserControl 
    x:Class="MTGenome.Views.GameSurfaceView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:ui="clr-namespace:MTGenome.UI;assembly=MTGenome.UI"
    xmlns:caliburn="http://www.caliburnproject.org"
    mc:Ignorable="d" 
    d:DesignHeight="300" d:DesignWidth="300">
    <ItemsControl ItemsSource="{Binding CardsInPlay}">
        <ItemsControl.ContextMenu>
            <ContextMenu>
                <MenuItem caliburn:Message.Attach="Draw" Header="_Draw" />
                <MenuItem caliburn:Message.Attach="Untap" Header="_Untap" />
                <MenuItem caliburn:Message.Attach="Shuffle" Header="_Shuffle" />
                <MenuItem caliburn:Message.Attach="Reset" Header="_Reset" />
            </ContextMenu>
        </ItemsControl.ContextMenu>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <Canvas>
                    <Canvas.Background>
                        <VisualBrush TileMode="Tile" Viewport="0,0,10,10" ViewportUnits="Absolute" Viewbox="0,0,10,10" ViewboxUnits="Absolute">
                            <VisualBrush.Visual>
                                <Border Width="10" Height="10" BorderThickness="0,0,1,1" BorderBrush="Gray" />
                            </VisualBrush.Visual>
                        </VisualBrush>
                    </Canvas.Background>
                </Canvas>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <ui:DraggableControl caliburn:Message.Attach="[Event MouseDoubleClick] = [Action ToggleTapped]">
                    <ui:DraggableControl.Template>
                        <ControlTemplate TargetType="ui:DraggableControl">                            
                            <Image Name="Image" Source="{Binding Image}" Width="111" Height="155" Stretch="Fill">
                                <Image.ToolTip>
                                    <ToolTip>
                                        <StackPanel Orientation="Vertical">
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="{Binding ManaCost}" />
                                                <TextBlock Margin="10,0,0,0" Text="{Binding Name}" />
                                            </StackPanel>
                                            <TextBlock Margin="0,10,0,0" ui:TextBlockBehavior.ItemsSource="{Binding Text}" TextWrapping="Wrap" />
                                            <TextBlock Text="{Binding PowerToughness}" />
                                        </StackPanel>
                                    </ToolTip>
                                </Image.ToolTip>
                            </Image>

                            <ControlTemplate.Triggers>
                                <DataTrigger Binding="{Binding Tapped}" Value="True">
                                    <Setter TargetName="Image" Property="RenderTransform">
                                        <Setter.Value>
                                            <RotateTransform Angle="90" CenterX="55.5" CenterY="77.5" />
                                        </Setter.Value>
                                    </Setter>
                                </DataTrigger>
                            </ControlTemplate.Triggers>

                        </ControlTemplate>
                    </ui:DraggableControl.Template>
                </ui:DraggableControl>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</UserControl>
